import { Component, OnInit, ViewChild, ElementRef } from '@angular/core';

import { RemoveTableService } from 'app/public/serve/remove-table/remove-table.service';
import { InitService } from 'app/public/serve/init/init.service';
import { IpRuleTableComponent } from './ip-rule-table/ip-rule-table.component';
import { Service } from '../../server/server';

import { ipRule } from './ip-rule.data';

declare var $:any; 

@Component({
  selector: 'app-ip-rule',
  templateUrl: './ip-rule.component.html',
})

export class IpRuleComponent implements OnInit {
  
  @ViewChild("table") table: IpRuleTableComponent;  

  ipRule: any = ipRule;
  
  right: any = { "system" : {}, "ip-rule" : {} };
  constructor(
    public initService: InitService,
    public removeTableService: RemoveTableService,
    public server:Service,
  ) { 
    this.right = $.extend(this.right, server.getRight());
  }
  
  // 控制侧边栏缩进
  isActive = this.server.isActive;
  ngOnInit() {
    ipRule.user['userId'] = sessionStorage.getItem('user');
    this.server.eventEmit.subscribe((value: any) => { this.isActive=value; });
  }

  ngDoCheck(){
    this.right = $.extend(this.right, this.server.getRight());
  }

  /**
   * 分页
   * @param pagination 
   */ 
  _pagination(pagination: Array<any>) { 

      ipRule.pagination.pageNumber = pagination[0].pageNumber;
      ipRule.pagination.pageSize   = pagination[0].pageSize;

      ipRule.pagination.naturalNum = (ipRule.pagination.pageNumber - 1) * ipRule.pagination.pageSize;

      this.table._table();
   }

  /**
   * 检索
   * @param val
   */  
  _retrieval(val: string) {
    ipRule.retrieval.queryCriteria = val.trim();
    this.table._table();
  }
}